package com.med.controller;

import com.med.common.ResponseDTO;
import com.med.entity.DepartmentDO;
import com.med.service.DepartmentService;
import com.med.vo.AddDepartmentVO;
import com.med.vo.QueryDepartmentVO;
import com.med.vo.UpdateDepartmentVO;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: Internet-based-healthcare
 * @BelongsPackage: com.med.controller
 * @Author: 小龚
 * @CreateTime: 2025-08-13 11:27
 * @Description: 科室管理
 * @Version: 1.0
 */
@RestController
@RequestMapping("/department")
public class DepartmentController extends BaseController {

    private final DepartmentService departmentService;

    @Autowired
    public DepartmentController(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    // 查询科室
    @GetMapping("/getDepartment")
    public AjaxResult getDepartment(QueryDepartmentVO vo) {
        System.out.println(vo);
        return AjaxResult.success(departmentService.getDepartment(vo));
    }


    // 更改科室状态
    @PutMapping("/updateStatus/{departmentId}")
    public AjaxResult updateStatus(@PathVariable Integer departmentId) {
        return AjaxResult.success(departmentService.updateStatus(departmentId));
    }

    //查询科室(redis预热、同步Redis、MySQL数据)
    @RequestMapping("/queryDepartment")
    public List<DepartmentDO> queryDepartment() {
        return departmentService.getDepartmentByPreheat();
    }


    // 查询所有的父级科室
    @GetMapping("/getParentDepartment")
    public ResponseDTO getParentDepartment() {
        return departmentService.getParentDepartment();
    }

    // 新增科室
    @PostMapping("/addDepartment")
    public AjaxResult addDepartment(@RequestBody AddDepartmentVO vo) {
        System.out.println(vo);
        return AjaxResult.success(departmentService.addDepartment(vo));
    }

    // 修改科室信息
    @PostMapping("/updateDepartmentInfo")
    public AjaxResult updateDepartmentInfo(@RequestBody UpdateDepartmentVO vo) {
        System.out.println(vo);
        return AjaxResult.success(departmentService.updateDepartmentInfo(vo));
    }

    // 删除科室
    @DeleteMapping("/deleteDepartment/{departmentId}")
    public AjaxResult deleteDepartment(@PathVariable Integer departmentId) {
        System.out.println(departmentId);
        return AjaxResult.success(departmentService.deleteDepartment(departmentId));
    }
}
